{% extends '::base.html.twig' %}

{% block title %}Lista subskrybentów{% endblock %}
 
{% block body %}
    
    {%block content %}
    <!-- content start -->
    <div class="well">
        <h1 class="heading">Wiadomości wysłane w kampanii {{campaign.name}}</h1>
        <ul>
            <li>Wszystkich wysłanych wiadomości w kampanii <span class="badge">{{campaign.messages|length}}</span></li>
        </ul>
        <a class="btn btn-primary btn-sm" href="{{path('wantuch_send_message_campaign', {'campaign_id':campaign.id})}}">Wyślij nową wiadomość</a>
        <table class="table table-striped table-hover ">
            <thead>
                <tr>
                    <th>ID</th>
                   
                    <th>Tytuł</th>
                    <th>Wysłana</th>
                    <th>Data wysłania</th>
                    
                    <th>Szczegóły</th>
                    <th>Edycja</th>
                </tr>
            </thead>
            <tbody>
            {% for message in campaign.messages %}
                <tr>
                    <td>{{message.id}}</td>
                    
                    <td>{{message.title}}</td>
                    <td>{{message.isSent}}</td>
                    <td>{{message.createdAt|date('d-m-Y H:i:s')}}</td>
                    <td><a href="#" class="show-details-modal details-button" data-id="{{message.id}}" data-toggle="modal" data-target="#detailsModal">Pokaż</a></td>
                    <td><a href="{{path("wantuch_edit_subscriber",{'id':message.id})}}">Edytuj</a></td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
        
    </div>
    <!-- Modal -->
    <div class="modal fade" id="detailsModal" tabindex="-1" role="dialog" aria-labelledby="detailsModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only"></span></button>
                    <h4 class="modal-title" id="detailsModalLabel">Szczegóły kampanii</h4>
                </div>
                <div class="modal-body">
                   
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-dismiss="modal" >Zamknij</button>
                </div>
            </div>
        </div>
    </div>
    <!-- End modal --> 
    <!-- content end -->
    {% endblock %}
    {% block javascripts %}
        {{ parent() }}
        
        <script type="text/javascript">
            $(document).ready(function(){
                $('.details-button').on('click',function(){
                    
                    $.ajax({
                        type: "POST",
                        url: "{{path('wantuch_mailer_ajax_details_message')}}",
                        data: { id: $(this).data("id") }
                    })
                        .done(function( msg ) {
                            $("#detailsModal .modal-body").html(msg.data);
                        });
                });
            });
        </script>
    {% endblock %}
    {% block footer %}{% endblock %}
{% endblock %} 